Skip to content

Measure which legacy branches this chain ever took - #409

Merged
SergioDemianLerner merged 5 commits into
mainfrom
census/legacy-branch-instrumentation
Nov 22, 2026
Merged

SergioDemianLerner merged 5 commits into
mainfrom
census/legacy-branch-instrumentation

Conversation

@SDL-A1

@SDL-A1 SDL-A1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Every activation that changes behaviour leaves a branch behind, guarded by a height test. A branch over a window that can never reopen is a candidate for deletion — but only if nothing in the window ever took it, and that is a claim about history, not about the code. Removing such a guard on reasoning alone would change the state root this node computes for blocks that are already on the chain.

The expensive part of proving it is the replay. The counting is nearly free. So a replay that answers one of these questions should answer all of them, and this turns one historical re-execution into a measurement of a dozen rows.

One rule is already settled by this branch, in 219 seconds. See EVM-073 below.

The registry — nine rows

legacy_census declares the enum, the index and the description in one macro so they cannot drift apart. A row costs one line there plus one hit() where the branch is taken.

rule branch window (mainnet)
BR-086 funds-migration end age is 172,800 blocks, not 10,585 #4,976,300 – #5,468,000
EVM-024 a bridge transaction from a privileged sender executes free below #370,000
BR-015 receiveHeaders is public rather than federation-only #1,591,000 – #3,614,800
BR-030 an internal call to the bridge ends its caller below #729,000
BR-011a a bridge method a later activation removed was invoked while it existed below #729,000 or #1,591,000
EVM-033 a contract created at a funded address loses that balance below #3,614,800
EVM-034 an internally created contract's nonce is 0, not 1 below #1,591,000
EVM-046 a dirty-high-bits address reaches the account, not the precompile all heights
PC-042 a block-header depth outside 0..32,767 all heights

The last two are not deletion candidates — they are live at every height on every network. They are measured for a different reason, given below.

Two positive controls, and a report that refuses to be read without one

A campaign that only ever returns zero has not been validated. A counter that cannot fire reports zero exactly as convincingly as a branch nothing ever took. That matters more now that three of the nine rows measure behaviour which cannot be removed: a broken counter would look identical to the answer everyone expects.

BR-086's window is known occupied — using the ordinary end age inside it diverged a real mainnet block — so reexec_all prints a verdict:

POSITIVE CONTROL DID NOT FIRE. Either this run did not cover #4,976,300..#5,468,000,
or the counters are not wired to the branches they name. Until that is resolved,
treat every zero above as unproven.

EVM-024 is the second control: it exists precisely because the bootstrap-era federation needed it.

Rows counted more carefully than "the branch was reached"

  • EVM-033 fires only when a balance is actually lost. Without the branch the balance would be what was there plus what was sent, so the outcome differs exactly when the address already held funds. Counting every creation would give a large number that answers nothing.
  • EVM-034 needed set_created_contract_nonce to report whether it applied: the internal-frame path handles calls and creations alike, and the top-level path also passes nonce 0, so a naive counter could not tell the legacy branch from either.
  • BR-015 is deliberately an over-count — any call to receiveHeaders while the window is open, not only one from a caller the federation-only rule would have refused. An over-count that returns zero is still a proof; only a non-zero needs the finer question asked.
  • BR-011a is counted where the method resolves, not by scanning transaction inputs. The catalogue's method for these six is a selector scan, which is structurally blind to the cases its own note describes: four of the six are local-only getters whose only on-chain caller is a contract, and an internal call carries no transaction input. parsed is Some only when the method is enabled at that height, so reaching it with one of the six signatures is the window being used — by a transaction or a contract alike.
  • PC-042 counts both arms: a depth in −32,768..−1 reaches the sign test and throws, one outside the 16-bit range is refused by the narrowing and answers empty. The positive side is deliberately not counted — 5,000 and 40,000 both answer empty by different routes, so the narrowing is already invisible there, which halves the claim to be proved.

One row dropped rather than shipped

BR-012 (a local-only bridge method reached by an on-chain call) cites a line that is the no-data releaseBtc path — a different rule. By this change's own logic, a counter attached to the wrong branch reports zero as convincingly as a clean window, so it is better absent than misleading.

Three behaviours with their own counters

Each carries a quantity a bare hit count would lose:

  • Seven-operand STATICCALL (RSKIP-91 → RSKIP-103, #729,000 – Security/supply chain hardening #1,052,700): executions, and those carrying a non-zero value. For that window "a static call cannot change state" is false on this chain — calculateCallValue excepted only DELEGATECALL, so the value was transferred. Counted where the operands are read, so a call that later fails for gas still counts: the question is what the opcode was passed.
  • The two empty-deploy branches below RSKIP-453, plus the largest code any internal creation returned. The maximum is the useful negative evidence — a figure well under the 24,576-octet limit says the oversize branch was never close to firing.
  • Contracts deployed, and how many carried the RSK code header (issue Was any contract ever deployed with an RSK code header? #405).

EVM-073 — settled, and the screen that made it cheap

tx_signature_v answers whether any transaction ever carried v = 34, an octet EIP-155 cannot produce which means exactly what 28 means. A single hit kills the narrowing proposal, because such a transaction sits in a valid block whose sender was recovered from it.

Two modes: an exact walk of canonical blocks at ~370 a second (seven hours for the chain), and --screen, which iterates the bodies column family sequentially at ~58,800 bodies a second — under four minutes, 160×.

Result: no v = 34 in any stored body, across 12,799,779 bodies and 31,210,944 transactions, none undecodable, 219 seconds.

            v        count  meaning
            0   12,799,778  no signature
           27      951,612  legacy, pre-EIP-155
           28      951,791  legacy, pre-EIP-155
           95    8,251,088  chain 30, mainnet
           96    8,256,675  chain 30, mainnet

Three things worth keeping beyond the zero: v = 0 is one per body but for a single exception, which is REMASC and the check that the instrument read real transactions; 1.9 million transactions are pre-EIP-155, so anything recovering a chain id from v is wrong for 6% of this chain; and no value in 29..=33 appears, which would have been a finding about the store or the decoder rather than about the chain.

The screen is one-directional and says so: it covers non-canonical bodies, so nothing found settles the canonical question outright while a hit needs the exact walk. It counts bodies it cannot decode and refuses to report a clean screen while any remain — a pass that silently skipped some would report a zero it had not earned.

BR-134 — a receipts scan, no replay

The bridge sizes a single dynamic event field as ((len - 1) / 32 + 1) * 32 in signed truncating division, so an empty field emits one zero word and the data is 96 octets where the canonical ABI gives 64.

bridge_event_width scans stored receipts — the evidence is what the chain recorded, which is what binds. "Data is exactly 96 octets" is not the test: the encoding is offset(32) ++ length(32) ++ content padded to whole words, so a field of 1 to 32 octets is also exactly 96, legitimately, a 32-octet hash being the ordinary case. The test is 96 octets and a declared length of zero, and both numbers are reported so the gap is visible. ~3.1 h for the chain; a probe over #1..#120,000 read 5,158 bridge logs and found none at 96 octets.

EVM-046 — why its proposed screen cannot work

The screen was: such a call touches the account at the precompile address, a touched account is materialised, no ordinary path materialises one — so an absent account would prove non-occurrence in seconds.

The premise is false. BlockExecutor.maintainPrecompiledContractStorageRoots creates every genesis precompile at the RSKIP-126 activation and re-creates each consensus-enabled one at its own. Checked against mainnet state at #9,238,111 with opcode_census --account, all seven tested precompile addresses exist. The screen reports "materialised" whatever the history, and a reader taking that as evidence toward occurrence would conclude the opposite of the truth.

A second hole would have remained even had the premise held: call_without_code touches the callee only under CallValue::Transfer. A zero-value transfer does touch — revm's transfer_loaded calls touch_account before returning — so STATICCALL would have been covered, but DELEGATECALL passes CallValue::Apparent, never enters that branch, and leaves no trace.

So the replay counter is load-bearing here rather than confirmatory.

Siting

Each counter sits where the quirk's own path diverges rather than behind a height test — rsk_static_call_with_value is installed only below RSKIP-103, rsk_return_create is reached only below RSKIP-453 at depth > 0 — so reaching one already means its era applies, and no block outside the window can be counted.

reexec_all prints every total beside its verdict, including on an incomplete run, with the block counts so a zero is always read against the range that produced it.

The report

docs/retroactive-guard-measurements.md records what has been measured, with the exact command and the widening knob for each tool, separating results that exist from counters that are merely wired. It keeps the two negative results as well, because a measurement method that does not work is worth as much to the next person as one that does. It also states the limits: mainnet only, so every result is half the claim; several windows are empty on testnet rather than unoccupied.

Execution 1,912 pass; clippy clean.

🤖 Generated with Claude Code

SergioDemianLerner and others added 5 commits November 22, 2026 00:52
Every activation that changes behaviour leaves a branch behind, guarded by a
height test. A branch over a window that can never reopen is a candidate for
deletion -- but only if nothing in the window ever took it, and that is a claim
about history, not about the code. Removing such a guard on reasoning alone
would change the state root this node computes for blocks that are on the chain.

The expensive part of proving it is the replay; the counting is nearly free. So
a replay that answers one of these questions should answer all of them, and
this turns one historical re-execution into a measurement of a dozen rows.

`legacy_census` is the registry. A macro declares the enum, the index and the
description together so they cannot drift apart, and a row costs one line there
plus one `hit()` where the branch is taken. Six are wired:

    BR-086  funds-migration end age is 172,800 blocks, not 10,585
    EVM-024  a bridge transaction from a privileged sender executes free
    BR-015  receiveHeaders is public rather than federation-only
    BR-030  an internal call to the bridge ends its caller
    EVM-033  a contract created at a funded address loses that balance
    EVM-034  an internally created contract's nonce is 0, not 1

**Two of those are positive controls, and the report refuses to be read without
the first.** A campaign that only ever returns zero has not been validated: a
counter that cannot fire reports zero exactly as convincingly as a branch
nothing took. `BR-086`'s window is known occupied -- using the ordinary end age
inside it diverged a real mainnet block -- so `reexec_all` prints a verdict
saying that every other zero is unproven until that one fires. `EVM-024` is the
second: it exists because the bootstrap-era federation needed it.

Three of the six are counted more carefully than "the branch was reached":

- `EVM-033` fires only when a balance is actually lost. Without the branch the
  balance would be what was there plus what was sent, so the outcome differs
  exactly when the address already held funds; counting every creation would
  give a large number that answers nothing.
- `EVM-034` needed `set_created_contract_nonce` to report whether it applied,
  because the internal-frame path handles calls and creations alike and the
  top-level path also passes nonce 0 -- so a naive counter could not tell the
  legacy branch from either.
- `BR-015` is deliberately an over-count: it fires for any call to
  `receiveHeaders` while the window is open, not only one from a caller the
  federation-only rule would have refused. An over-count that returns zero is
  still a proof, and only a non-zero needs the finer question asked.

A seventh row was dropped rather than shipped. `BR-012` -- a local-only bridge
method reached by an on-chain call -- cites a line that is the no-data
`releaseBtc` path, a different rule. By this change's own logic, a counter
attached to the wrong branch would report zero as convincingly as a clean
window, so it is better absent.

Alongside the registry, three behaviours with their own counters because each
carries a quantity a bare hit count would lose:

- seven-operand `STATICCALL` (RSKIP-91 to RSKIP-103, mainnet #729,000 to
  #1,052,700), counting executions and those carrying a non-zero value. For
  that window "a static call cannot change state" is false on this chain:
  `calculateCallValue` excepted only `DELEGATECALL`, so the value was
  transferred. Counted where the operands are read, so a call that later fails
  for gas still counts -- the question is what the opcode was *passed*.
- the two ways an internal creation below RSKIP-453 deploys empty instead of
  reverting, with the largest code any such creation returned. The maximum is
  the useful negative evidence: a figure well under the 24,576-octet limit says
  the oversize branch was never close to firing, which is stronger than "it did
  not fire".
- contracts deployed, and how many carried the RSK code header.

Each counter sits where the quirk's own path diverges rather than behind a
height test -- `rsk_static_call_with_value` is installed only below RSKIP-103,
`rsk_return_create` is reached only below RSKIP-453 at depth > 0 -- so reaching
one already means its era applies and no block outside the window can be
counted.

`reexec_all` prints every total beside its verdict, including on an incomplete
run, because a run that stopped early still observed what it executed, and with
the block counts so a zero is always read against the range that produced it.

Execution 1,913; clippy clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The address operand of the call opcodes is a 256-bit word of which only the low
20 octets are the address. Where that word has a bit set above bit 159 *and* its
low 20 octets name an active precompile, the reference looks the precompile up
by the whole word, finds none, and calls the truncated address instead -- so the
precompile does not run, the call succeeds, returns nothing and keeps its gas.
An Ethereum-derived client truncates first, runs the precompile, and diverges in
the returned data, the gas, and any state the precompile would have written.

This is not a guard anyone can remove: it holds at every height on every
network. Its occupancy is worth knowing for a different reason -- whether this
chain contains a block an Ethereum-derived client would get wrong -- so it joins
the census labelled as permanent, measured for divergence rather than deletion,
and the module note no longer claims every row is a deletion candidate.

The counter sits on `to_account`, which is already exactly the predicate:
`past_an_address && the callee is an active precompile`. Every call opcode,
every frame depth.

A state screen was proposed instead of the replay: such a call touches the
account at the precompile address, a touched account is materialised, and no
ordinary path materialises a precompile address -- so an absent account would
prove non-occurrence in seconds rather than hours.

**The premise is false, and the screen inverts the answer it gives.** rskj's
`BlockExecutor.maintainPrecompiledContractStorageRoots` creates every genesis
precompile at the RSKIP126 activation block and re-creates each
consensus-enabled one at its own activation. Checked against mainnet state at
#9,238,111, all seven tested precompile addresses exist as accounts. The screen
therefore reports "materialised" whatever the history, and a reader taking that
as evidence toward occurrence would conclude the opposite of the truth.

A second hole would have remained even had the premise held. `call_without_code`
touches the callee only under `CallValue::Transfer`. A zero-value transfer does
touch -- revm's `transfer_loaded` calls `touch_account` before returning -- so
`STATICCALL`, which passes `Transfer(ZERO)`, would have been covered. But
`DELEGATECALL` passes `CallValue::Apparent`, never enters that branch, and
leaves no trace: one of the four call opcodes invisible to the screen.

So the counter is load-bearing here rather than confirmatory.

`opcode_census --account` is what settled it: one trie lookup per address
against a chosen height, no walk. It is in the tool because the next premise of
this shape deserves two seconds of checking rather than an argument.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The bridge sizes a single dynamic `bytes`/`string` event field as
`((len - 1) / 32 + 1) * 32` in signed truncating division, so an empty field
emits one zero word and the data is 96 octets where the canonical ABI gives 64
(BR-134). Whether any caller ever produced one is a question about the chain,
and the evidence is in the receipts rather than in the execution -- so unlike
the rest of this campaign it needs no replay.

"Data field is exactly 96 octets" is not the test, though it is the obvious
one. The encoding is `offset(32) ++ length(32) ++ content`, content padded to
whole words, so a field of 1 to 32 octets is also exactly 96 -- legitimately,
and commonly, a 32-octet hash being the ordinary case. What distinguishes the
quirk is the length word: 96 octets *and* a declared length of zero. Both
numbers are reported, because the gap between them is what shows the sharper
test was needed.

Filtered by bridge address and data shape rather than by the four named event
topics. The encoder is shared, so a later event with an optional dynamic field
inherits the behaviour, and a shape filter catches those too; the topic of any
hit is printed so a reader can say which event it was.

Receipts rather than execution is the point. What binds is what the chain
recorded: an argument that today's callers are all non-empty is a fact about
code, and an early release that logged an empty field would have frozen the
96-octet form into a receipts root whatever today's code says.

Measured at 840 blocks/s, so the whole chain is about 3.1 hours -- cheaper than
a replay, and it needs no node stopped. A probe over #1..#120,000 read 5,158
bridge logs and found none at 96 octets, which is the instrument reading real
data rather than finding nothing because it is broken.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
**BR-011a — six bridge methods that existed only in a window.** Enabled from
genesis, disabled at an activation, after which the selector resolves nothing
and is indistinguishable in a receipt from an unknown one.

The catalogue's method for these is a selector scan of transaction inputs, which
needs no replay and is ranked the cheapest measurement available. It is also
structurally blind to the cases its own note describes: four of the six are
local-only getters whose only on-chain caller is a contract, and an internal
call carries no transaction input. So the scan settles "no transaction carried
one of these selectors" and says nothing about contracts.

Counted where the method resolves instead. `parsed` is `Some` only when the
method is enabled at that height, so reaching it with one of the six signatures
is the window being used -- by a transaction or by a contract alike. Each hit
logs which signature, so one run still settles the six rules separately.

**PC-042 -- the block-header depth narrowed before its sign is tested.** The
depth argument is an `int256` narrowed to a signed 16-bit value *before* the
negative test, so -1 throws and -40,000 does not. The asymmetry is the point: a
throw costs the caller all its gas -- all of it, from a contract below
RSKIP-197 -- where empty bytes is a successful return.

Both arms of the predicate count: a depth in -32,768..-1 reaches the sign test,
and one outside the 16-bit range is refused by the narrowing. Both are outside
0..32,767. The positive side is deliberately not counted as a finding: 5,000 and
40,000 both answer empty by different routes, so the narrowing is already
invisible there and removing it would change nothing for any input. That halves
the claim to be proved.

Needs a replay rather than a receipts scan, because a contract-internal call's
input is in no receipt.

Neither row is a deletion candidate. Both are live at every height, which is
why the module note no longer claims every row is one -- and why the positive
controls matter: a third of the census now measures behaviour that cannot be
removed, where a silently broken counter would look exactly like the result
everyone expects.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…sured

**`tx_signature_v`.** The signature octet `v` is decomposed as
`chainId = (v - 35) / 2` with the subtraction floored at zero, accepted set
`27, 28, 34 … 255`. So `v = 34` is accepted and means exactly what `28` means,
and is not a value EIP-155 can produce; narrowing the set to `27, 28, 35 …`
would be a de-divergence rather than a special case moved elsewhere. A single
`v = 34` kills that proposal, because such a transaction sits in a valid block
whose sender was recovered from it.

Two modes. The exact walk reads canonical blocks at about 370 a second, which
is seven hours for the chain. `--screen` iterates the bodies column family
sequentially instead -- no canonical-hash lookup, no random read per block --
at about 58,800 bodies a second, which is under four minutes. 160x.

The screen is one-directional and says so: it covers non-canonical bodies too,
so nothing found settles the canonical question outright, while a hit needs the
exact walk over the range concerned, because a transaction in an orphaned block
invalidates nothing. It counts bodies it cannot decode and refuses to report a
clean screen while any remain -- a pass that silently skipped some would report
a zero it had not earned.

**Result: settled for mainnet.** No `v = 34` in any stored body, across
12,799,779 bodies and 31,210,944 transactions, none undecodable, 219 seconds.
Three things in the histogram are worth keeping beyond the zero: `v = 0` is one
per body but for a single exception, which is REMASC and the check that the
instrument read real transactions; **1.9 million transactions are pre-EIP-155**,
signed 27 or 28, so anything recovering a chain id from `v` is wrong for 6% of
this chain; and no value in `29..=33` appears, which would have been a finding
about the store or the decoder rather than about the chain.

**`docs/retroactive-guard-measurements.md`** records what has been measured,
with the exact command and the widening knob for each tool, separating results
that exist from counters that are merely wired. It keeps the two negative
results as well: the proposed state screen for `EVM-046` cannot work, because
every precompile address already exists as an account, and the `BR-134`
predicate needs the length word rather than the 96-octet width alone. A
measurement method that does not work is worth as much to the next person as
one that does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@SDL-A1
SDL-A1 force-pushed the census/legacy-branch-instrumentation branch from 56bbb4a to 5055fe7 Compare November 22, 2026 02:50
@SergioDemianLerner
SergioDemianLerner merged commit fe3819e into main Nov 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants